<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>component-state</title>
</head>
<body>
  <div id="app"></div>
  <script type="text/javascript" src="../js/react.js"></script>
  <script type="text/javascript" src="../js/react-dom.js"></script>
  <script type="text/javascript">
    var myTextArea = React.createClass({
      propTypes: {
        text: React.PropTypes.string,
      },

      getDefaultProps: function(){
        return {
          text: "",
        }
      },

      getInitialState: function() {
        return {
          text: this.props.text,
        }
      },

      _textChange: function(ev) {
        this.setState({
          text: ev.target.value
        });
      },

      render: function() {
        return React.DOM.div(null,
          React.DOM.textarea({
            value: this.state.text,
            onChange: this._textChange,
          }),
          React.DOM.h1(null, this.state.text.length)
        );
      }


      // 静态
      // render: function(){
      //   return React.DOM.div(null,
      //     React.DOM.textarea({
      //       defaultValue: this.props.text,
      //     }),
      //     React.DOM.h1(null, this.props.text.length)
      //   );
      // }
    });

    ReactDOM.render(
      React.createElement(myTextArea,{text: "My name is Bob"}),
      document.getElementById("app")
    );

  </script>
</body>
</html>
